package com.ruoyi.web.controller.workcategory;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.LhqWorkCategory;
import com.ruoyi.service.ILhqWorkCategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 著作类别Controller
 * 
 * @author ruoyi
 * @date 2020-09-08
 */
@Controller
@RequestMapping("/ruoyi/category")
public class LhqWorkCategoryController extends BaseController
{
    private String prefix = "ruoyi/category";

    @Autowired
    private ILhqWorkCategoryService lhqWorkCategoryService;

    @RequiresPermissions("ruoyi:category:view")
    @GetMapping()
    public String category()
    {
        return prefix + "/category";
    }

    /**
     * 查询著作类别列表
     */
    @RequiresPermissions("ruoyi:category:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LhqWorkCategory lhqWorkCategory)
    {
        startPage();
        List<LhqWorkCategory> list = lhqWorkCategoryService.selectLhqWorkCategoryList(lhqWorkCategory);
        return getDataTable(list);
    }

    /**
     * 导出著作类别列表
     */
    @RequiresPermissions("ruoyi:category:export")
    @Log(title = "著作类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LhqWorkCategory lhqWorkCategory)
    {
        List<LhqWorkCategory> list = lhqWorkCategoryService.selectLhqWorkCategoryList(lhqWorkCategory);
        ExcelUtil<LhqWorkCategory> util = new ExcelUtil<LhqWorkCategory>(LhqWorkCategory.class);
        return util.exportExcel(list, "category");
    }

    /**
     * 新增著作类别
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存著作类别
     */
    @RequiresPermissions("ruoyi:category:add")
    @Log(title = "著作类别", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LhqWorkCategory lhqWorkCategory)
    {
        return toAjax(lhqWorkCategoryService.insertLhqWorkCategory(lhqWorkCategory));
    }

    /**
     * 修改著作类别
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LhqWorkCategory lhqWorkCategory = lhqWorkCategoryService.selectLhqWorkCategoryById(id);
        mmap.put("lhqWorkCategory", lhqWorkCategory);
        return prefix + "/edit";
    }

    /**
     * 修改保存著作类别
     */
    @RequiresPermissions("ruoyi:category:edit")
    @Log(title = "著作类别", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LhqWorkCategory lhqWorkCategory)
    {
        return toAjax(lhqWorkCategoryService.updateLhqWorkCategory(lhqWorkCategory));
    }

    /**
     * 删除著作类别
     */
    @RequiresPermissions("ruoyi:category:remove")
    @Log(title = "著作类别", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lhqWorkCategoryService.deleteLhqWorkCategoryByIds(ids));
    }
}
